package com.puzzlebazar.client.util;

import com.google.gwt.user.client.rpc.AsyncCallback;

public class AsyncCallbackLock<T> implements AsyncCallback<T> {

	private final ConnectionLock lock;
	
	public AsyncCallbackLock( ConnectionLock lock ) {
		super();
		this.lock = lock;
		lock.grab();
	}

	// Subclass must call!
	@Override
	public void onFailure(Throwable caught) {
		lock.release();
	}

	// Subclass must call!
	@Override
	public void onSuccess(T result) {
		lock.release();
	}

}
